﻿using MC;
using Newtonsoft.Json;
using Station.Common.Rejudgment;
using Station.Inspect.SuaModel;
using Station.Inspect.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vision.Common;

namespace Station.Inspect
{
    public class Project
    {
        #region 参数配置
        public int LineMode { get; set; } = 1;
        public string FaceName { get; set; } = "A";
        public int g_nImageTimer { get; set; } = 100;
        public double g_dMaxVel { get; set; } = 300;
        public TargetPos Pixel2mm = new TargetPos(148.46, 148.46, 148.46);
        #endregion


        #region 缩略图相关
        public TargetPos sketchOrig1 = new TargetPos();
        public TargetPos sketchOrig = new TargetPos();
        public TargetPos sketchSize = new TargetPos();
        public double sketchProp = 0.03;
        [JsonIgnore]
        public Bitmap sketchImg;
        #endregion

        #region 程式相关
        public TargetPos pathLT = new TargetPos();
        public TargetPos pathRT = new TargetPos();
        public TargetPos pathLB = new TargetPos();
        public Size pathSize = new Size(1, 1);
        [JsonIgnore]
        public int pathEx = 10;
        //[JsonIgnore]
        //spublic List<ErrCell> ErrCells { get; set; } = new List<ErrCell>();
        #endregion

        #region 程式相关2
        //public List<NodeLib> Libs = new List<NodeLib>();
        public List<NodeComponent> Components { get; set; } = new List<NodeComponent>();
        public List<NodeMark> Marks { get; set; } = new List<NodeMark>();
        #endregion

        #region 模型
        //[JsonIgnore]

        #endregion

        public Point TP2Point(TargetPos pos)
        {
            var p = new Point((int)(pos.x * Pixel2mm.x), (int)(pos.y * Pixel2mm.y));
            return p;
        }

        public void UpdateLib()
        {
            IsUseMatrix = false;
            IsUseLable = false;
            IsUseBadMark = false;
            foreach (var nodeMark in Marks)
            {
                nodeMark.Reset(false);
                nodeMark.SrcImage = null;
                nodeMark.DstImage = null;
            }
            foreach (var comp in Components)
            {
                comp.Reset(false);
                foreach (var item in comp.Elements)
                {
                    var lib = NodeLibManager.Find(item.LibID);
                    item.Lib = lib;
                    //-- 判断是否需要打码
                    if (lib is NodeLib)
                    {
                        NodeLib curlib = lib as NodeLib;
                        if (lib.IsBadMarkPos)
                        {
                            IsUseBadMark = true;
                        }
                        if (lib.IsLablePos)
                        {
                            IsUseLable = true;
                        }

                        if (lib.IsMatrixPos)
                        {
                            IsUseMatrix = true;
                        }
                    }
              
                }
            }
        }

        public void Reset()
        {
            foreach (var nodeMark in Marks)
            {
                nodeMark.Reset();
                nodeMark.SrcImage = null;
                nodeMark.DstImage = null;
            }
            foreach (var comp in Components)
            {
                comp.Reset();
            }
        }
        #region 打码设置相关
        /// <summary>
        /// 二维码
        /// </summary>
        public bool IsUseMatrix { get; set; } = false;
        /// <summary>
        /// 明码
        /// </summary>
        public bool IsUseLable { get; set; } = false;
        /// <summary>
        /// BadMark
        /// </summary>
        public bool IsUseBadMark { get; set; } = false;
        #endregion
        #region 光源控制相关
        public string lightCOM { get; set; }
        public int lightChannel { get; set; }
        public int brightness { get; set; }
        #endregion
    }
}
